/**
 * Project Name:UserSynServiceImpl
 * File Name:UserSynServiceImpl.java
 * Package Name:com.bwda.dsrs.systemservice.service
 * Date:2019年4月28日
 * Copyright (c) 2019, 江苏保旺达软件有限公司 All Rights Reserved.
 */
package com.bwda.dsrs.systemservice.service.impl;

import com.bwda.dsrs.systemservice.domain.form.user.UserExcelImport;
import com.bwda.dsrs.systemservice.domain.form.user.UserRoleForm;
import com.bwda.dsrs.systemservice.mapper.UserMapper;
import com.bwda.dsrs.systemservice.service.UserSynService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 针对每个用户异常回滚操作
 *
 * @author youzhen
 * @date 2019/4/27
 */
@Service
public class UserSynServiceImpl implements UserSynService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 添加用户角色
     *
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertUser(UserExcelImport user, String creatUserCode, int orgId) {
        user.setCreateUserCode(creatUserCode);
        user.setOrgId(orgId);
        int row = userMapper.importUser(user);
        //用户角色绑定
        int roleId = userMapper.queryRole();
        UserRoleForm userRoleForm = new UserRoleForm();
        userRoleForm.setUserCode(user.getUserCode());
        userRoleForm.setRoleId(roleId);
        userMapper.insertRole(userRoleForm);
        return row;
    }
}